#ifndef _SPI_H_
#define _SPI_H_

#include "ssi.h"


typedef enum {
    SPI_CS_0 = 0x0,
    SPI_CS_1,
    SPI_CS_2,
    SPI_CS_3,
} spi_cs_t;

typedef enum {
    // tx: 01 02 03
    // rx: 0a 0b 0c
    SPI_TMOD_TX_RX = 0x0,
    // tx: 01 02 03
    // rx: -- -- --
    SPI_TMOD_TX_ONLY,
    // tx: -- -- --
    // rx: 0a 0b 0c
    SPI_TMOD_RX_ONLY,
    // tx: 01 02 03
    // rx: -- -- -- 0a 0b 0c
    SPI_TMOD_EEPROM_READ,
} spi_tmod_t;

typedef enum {
    SPI_CFS_01_BIT = 0x0,
    SPI_CFS_02_BIT,
    SPI_CFS_03_BIT,
    SPI_CFS_04_BIT,
    SPI_CFS_05_BIT,
    SPI_CFS_06_BIT,
    SPI_CFS_07_BIT,
    SPI_CFS_08_BIT,
    SPI_CFS_09_BIT,
    SPI_CFS_10_BIT,
    SPI_CFS_11_BIT,
    SPI_CFS_12_BIT,
    SPI_CFS_13_BIT,
    SPI_CFS_14_BIT,
    SPI_CFS_15_BIT,
    SPI_CFS_16_BIT,
} spi_cfs_t;

typedef enum {
    SPI_FRF_STAND = 0x0,
    SPI_FRF_DUAL,
    SPI_FRF_QUAD,
    // SPI_FRF_OCTAL,
} spi_frf_t;

typedef enum {
    SPI_IS_SLAVE = 0x0,
    SPI_IS_MASTER,
} spi_ismst_t;

typedef struct {
    spi_ismst_t is_master;
    spi_cs_t    chip_select;
    spi_cfs_t   ctrl_frame_size;
    spi_frf_t   frame_format;
    spi_tmod_t  transfer_mode;

    uint8_t     rxoffs;
    void        *txbuf; // buffer should be uint8_t or uint16_t since ctrl_frame_size in [1, 16]
    void        *rxbuf;

    ssi_addr_t  *port;
} spi_t;

#endif
